package com.example.practice.controller;

import com.example.practice.entity.JsonResponse;
import com.example.practice.entity.StudentLocation;
import com.example.practice.service.StudentLocationService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (StudentLocation)表控制层
 *
 * @author makejava
 * @since 2024-01-04 10:23:06
 */
@RestController
@RequestMapping("/api/studentLocation")
public class StudentLocationController {
    /**
     * 服务对象
     */
    @Resource
    private StudentLocationService studentLocationService;

    /**
     * 分页查询
     *
     * @param studentLocation 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<StudentLocation>> queryByPage(StudentLocation studentLocation, PageRequest pageRequest) {
        return ResponseEntity.ok(this.studentLocationService.queryByPage(studentLocation, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param uid 主键
     * @return 单条数据
     */
    @GetMapping("queryById")
    public StudentLocation queryById(Integer uid,Integer aid) {
        return this.studentLocationService.queryById(uid,aid);
    }

    /**
     * 新增数据
     *
     * @param studentLocation 实体
     * @return 新增结果
     */
    @PostMapping("insert")
    public JsonResponse insert(@RequestBody StudentLocation studentLocation) {
        int i=this.studentLocationService.insert(studentLocation);
        return JsonResponse.success(i);
    }

    @GetMapping("/deleteStudentLocation")
    public Integer deleteById(Integer uid,Integer aid) {
        return this.studentLocationService.deleteById(uid,aid);
    }

}

